package com.rule.knowledge.base.db;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
import java.io.Serializable;
/**
 * 存储数据的规则模型
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "rules")
@IdClass(RuleDbModel.IdClass.class)
public class RuleDbModel {

    /**
     * 规则名称空间，需唯一
     * 命名空间：用于识别或将域的相同类型的规则合并为一个
     */
    @Id
    @Column(name = "rule_namespace")
    private String ruleNamespace;

    /**
     * 规则id，需唯一
     * 每个规则都可以用一些唯一的 Id 来标识
     */
    @Id
    @Column(name = "rule_id")
    private String ruleId;

    /**
     * 规则条件
     */
    @Column(name = "condition")
    private String condition;

    /**
     * MVEL+DSL形式的Rule动作
     * 规则动作
     */
    @Column(name = "action")
    private String action;

    /**
     * 优先级：它将用于决定应首先对输入数据执行哪个规则
     * 规则优先级
     */
    @Column(name = "priority")
    private Integer priority;

    /**
     * 描述：显示规则的描述
     * 规则描述
     */
    @Column(name = "description")
    private String description;

    @Data
    static class IdClass implements Serializable {
        private String ruleNamespace;
        private String ruleId;
    }
}
